using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Media;

using Supremacy.Resources;

namespace SupremacyEditor
{
    public class EditorImageSourceConverter : ImageSourceConverter
    {
        private const string PlaceholderImageUri = "vfs:///Resources/Images/TechObjects/__image_missing.png";

        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {
            var filePath = value as string;
            if (filePath != null)
            {
                var physicalFilePath = ResourceManager.GetResourcePath(filePath);
                if (!File.Exists(physicalFilePath))
                    value = PlaceholderImageUri;
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }
    }
}